package model.player;

import java.util.LinkedList;
import java.util.List;

public class ManagerCycler implements ControllablePlayer 
{
	
	private UnitTypeManager unitTypeManager;
	private StructureTypeManager structureTypeManager;
	private RallyPointTypeManager rallyPointManager;
	
	private List<SubTypeManager> managers;
	private int ptr;

	public ManagerCycler()
	{
		unitTypeManager = new UnitTypeManager();
		structureTypeManager = new StructureTypeManager();
		rallyPointManager = new RallyPointTypeManager();
		ptr = 0;
		managers = new LinkedList<SubTypeManager>();
		
		managers.add(unitTypeManager);
		managers.add(structureTypeManager);
		managers.add(rallyPointManager);
	}
	
	public void setRallyPointManager(RallyPointManager rpm)
	{
		rallyPointManager.setRallyPointManager(rpm);
	}
	
	public void addUnitManager(UnitManager um)
	{
		unitTypeManager.addUnitManager(um);
	}
	
	public void addStructureManager(StructureManager sm)
	{
		structureTypeManager.addStructureManager(sm);
	}

	@Override
	public SubTypeManager getCurType()
	{
		return managers.get(ptr);
	}

	@Override
	public SubTypeManager getNextType() 
	{
		ptr = (ptr + 1) % managers.size();
		
		return managers.get(ptr);
	}

	@Override
	public SubTypeManager getPrevType() 
	{
		ptr = (ptr - 1 + managers.size()) % managers.size();
		
		return managers.get(ptr);
	}

}
